package com.baosight.sczx.zm.cl.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;

/**巡检路线配置树结构
 * <p>Title: ServiceZMCL90.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 高强
 * @version 1.0
 * <pre>Histroy:
 *           2011-3-30   高强   Create
 *</pre>
 */
public class ServiceZMCL90 extends TreeService {

	/**
	 * 查询根节点下的数据
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *     2011-3-30   高强   Create
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String p = (String) queryInfo.get(TreeConstants.TREE_NODE);
		String level = (String) queryInfo.get("level");
		List children = new ArrayList();
		if (p == null) {
			p = "$";
		}
		if ("$".equals(p)) {
			children = this.getTopNodes();//得到根节点
		} else {
			children = this.getChildNodes(p,level);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(p);
		block.setBlockMeta(initMetaData());
		block.setRows(children);
		return outInfo;
	}
	
	/**构造巡检路线配置树节点的孩子节点
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-30   高强   Create
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List getChildNodes(String arg0, String level) {
		String parentLabel = arg0;
		Map _argMap = new HashMap();
		_argMap.put(TreeConstants.TREE_NODE, parentLabel);
		
		String sql = "";
		List childNodes = null;
		if(level.equals("1"))
		{
			sql = "ZMCLSecurityPath.queryTreePath";
			childNodes = dao.query(sql, _argMap);
		}
		else if(level.equals("2"))
		{
			_argMap.put("fdStatus", "在用");
			sql = "ZMCLPointAssociation.queryTree";
			childNodes = dao.query(sql, _argMap);
		}
		return childNodes;
	}

	/**根节点构造
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return value: List</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-30   高强   Create
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List getTopNodes() {
		List topNodes = new ArrayList();
		Map map = new HashMap();
		map.put("label", "巡检路线配置");
		map.put("text", "top");
		map.put("level", "1");
		map.put("leaf", "0");
		topNodes.add(map);
		return topNodes;
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public List getChildNodes(String arg0) {
		return null;
	}
	
	/**数据列定义
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return value: EiBlockMeta</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-30   高强   Create
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setDescName("label");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("text");
		eiColumn.setDescName("text");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("level");
		eiColumn.setDescName("level");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("leaf");
		eiColumn.setDescName("leaf");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		return eiMetadata;
	}
}
